<extend name="Public:template" />
<block name="page_header">
	<include file="Public:header_with_title"/>
</block>
<block name="page_body">
<form action="{:U('Tuangou/doOrder')}" method="post" id="form_add" name="form_add" role="form">
<input type="hidden" name="address_add_flag" value="{$address.add_flag}">
<input type="hidden" name="prod_id" value="{$itemDetail.prod_id}">
<div class="row mt20">
	<div class="span20" id="stepOrder">
		<ul class="nav nav-tabs">
			<li class="active"><a href="{:U('Tuangou/showConfirm')}"><h4>第一步：预订商品</h4></a></li>
			<li class="disabled"><a href="#"><h4>第二步：等待收货</h4></a></li>
		</ul>
	</div>
	<div class="span10 mt-10">
		<table class="table table-bordered prodList">
			<tr class="alert-info">
				<th>预订商品</th>
				<th>规格</th>
				<th>价格</th>
			</tr>
			<tr>
				<td class="text-left">{$itemDetail.title} </td>
				<td><label class="label label-info">{$itemDetail.prod_spec}</label></td>
				<td class="text-right">¥{$itemDetail.price_real}</td>
			</tr>
			<tr>
				<td colspan="3" class="text-right">
					<div class="input-prepend">
						<span class="btn btn-success">可修改购买数量</span>
						<input type="text"  class="input-micro" id="prodNum" name="num" value="{$itemDetail.num}" onChange="updBuyNum('{$itemDetail.prod_id}',this.value)"/>
					</div>
				</td>
			</tr>
			<tr>
				<td colspan="3" class="text-right price">
					商品总价：<span class="now" id="totalAmt">¥{$itemDetail.total_amt|number_format=###, 2}</span>
				</td>
			</tr>
			<tr>
				<td colspan="3" class="text-right">
					免费配送
				</td>
			</tr>
		</table>
		
	</div>
	<div class="span10 mt-10">
			<input type="hidden" name="address_add_flag" value="{$address.add_flag}">
			<div class="input-prepend">
				<span class="btn btn-warning"><span class="icon-user"></span></span>
				<input type="text"  name="cust_name" placeholder="请输入收货人姓名" style="padding-left:5px;" value="{$address.name}">
			</div>
			<div class="input-prepend">
				<span class="btn btn-warning"><span class="icon-hdd"></span></span>
				<input type="text"  name="cust_mobile" placeholder="请输入收货人手机或电话" style="padding-left:5px;" value="{$address.mobile}">
			</div>
			<div class="input-prepend">
				<span class="btn btn-warning"><span class="icon icon-home"></span></span>
				<input type="text" class="input-xxlarge"  name="cust_address" placeholder="请输入您的收货地址" style="padding-left:5px;" value="{$address.address}">
			</div>
			<div class="input-prepend">
				<span class="btn btn-warning"><span class="icon icon-time"></span></span>
				<select name="cust_free_time" style="padding-left:5px" >
					<volist name="sendTime" id="val">
						<option value="{$val.title}">{$val.title}</option>
					</volist>
				</select>
			</div>
			<div class="input-prepend">
				<span class="btn btn-warning"><span class="icon icon-file"></span></span>
				<textarea name="cust_bak" class="input-xxlarge" rows=5 placeholder="如果有特殊说明或要求可在这里填写">{$address.content}</textarea>
			</div>
			<div class="alert alert-success">
				预购订单：我们会根据预订的先后顺序进行发货，为了保证商品质量，当天下的单，最快次日到达。
			</div>
			<button type="button"  class="btn btn-default btn-large mt5 pull-left" onclick="redirect('{:U('Tuangou/index')}')"><span class="icon icon-search"></span>我再逛逛</button>
			<button type="button"  class="btn btn-danger btn-large mt5 pull-right" onclick="doOrder()"><span class="icon-white icon-hand-right"></span>提交订单</button>
	</div>
</div>
<div id="confProd" class="modal hide fade">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			<h3>订单确认</h3>
	</div>
	<div class="modal-body">
		<table class="table table-bordered">
			<tr><td class="text-right">商品名称：</td><td class="text-left" id="confProdName">{$itemDetail.title} <label class="label label-info">{$itemDetail.prod_spec}</label></td></tr>
			<tr><td class="text-right">购买数量：</td><td class="text-left" id="confProdNum">{$itemDetail.num}</td></tr>
			<tr><td class="text-right">商品总额：</td><td class="text-left" id="confProdTotalAmt" >¥{$itemDetail.total_amt|number_format=###, 2}</td></tr>
			<tr><td class="text-right">配送信息：</td><td class="text-left" id="confAddress"></td></tr>
		</table>
	</div>
	<div class="modal-footer">
		<button type="button" class="btn btn-large" data-dismiss="modal" aria-hidden="true">取消</button>
		<button type="submit" class="btn btn-large btn-primary">确定</button>
	</div>
</div>

</form>
<br><br><br><br>
</block>
<block name="script_footer">
<script type="text/javascript">
function doOrder(){
	var formObj = document.forms["form_add"];
	var formElsObj = formObj.elements;
	if(formElsObj['cust_name'].value==''){
		alert('收货人名称不能为空');
		return false;
	}
	if(formElsObj['cust_mobile'].value==''){
		alert('联系电话或手机不能为空');
		return false;
	}
	if(formElsObj['cust_address'].value==''){
		alert('配送地址不能为空');
		return false;
	}
	if(formElsObj['num'].value==''||formElsObj['num'].value==0){
		alert('请输入购买数量');
		return false;
	}
	$("#confAddress").html(formElsObj['cust_name'].value+","+formElsObj['cust_mobile'].value+","+formElsObj['cust_address'].value);
	$('#confProd').modal('show');
}

function updBuyNum(prod_id,num){
	//问题 直接在底部不加载数据了
	//document.location.href = "/tuangou/updBuyNum.html?prod_id="+prod_id+"&num="+num;
	$.ajax({
		'async': false, 
        'url': "/tuangou/updBuyNum.html",
        'dataType': "json",
        'data': {'prod_id':prod_id,'num':num},
        'success': function (data) {
        	if(data['error']=='0'){
            	var item_num = data['item_num'];
            	var total_amt = data['total_amt'];
            	$('#prodNum').val(item_num);
            	$('#totalAmt').html("¥"+total_amt);
            	$("#confProdNum").html(item_num);
            	$("#confProdTotalAmt").html("¥"+total_amt);
            	if(data['message']!=""){
            		alert(data['message']);
            	}
        	}else{
        		alert(data['message']);
        	}
        	
        }
    });
}
</script>
</block>
